package castle_components
{
	import flash.display.MovieClip;
	
	import units.Unit;
	
	public class Tower extends MovieClip
	{
		public var BASE_WIDTH = 50,BASE_HEIGHT = 50;
		public var base_x = 0, base_y=0;
		public var ring_black:MovieClip;
		
		public var game_handler:GameHandler;
		
		public var registered_unit_1:Unit;
		public var registered_unit_2:Unit;
		
		public function Tower()
		{
			super();
			ring_black.gotoAndStop(0);
		}
		
		public function unit_action(u:Unit){
			if(u == registered_unit_1)
				u.attack();
			else if(u == registered_unit_2)
				u.attack();
			else{
				register(u);
			}
			
		}
		public function register(u:Unit){
			if(registered_unit_1 == null){
				registered_unit_1 = u;
				u.inside_of = this;
				u.x = this.x + game_handler.castle_center.x + 12;
				u.y = this.y + game_handler.castle_center.y + 10;
				return true;
			}else if(registered_unit_2 == null){
				registered_unit_2 = u;
				u.inside_of = this;
				u.x = game_handler.castle_center.x + this.x + 30;
				u.y = game_handler.castle_center.y + this.y + 10;
				return true;
			}
			else u.go_home();
			return false;
		}
		public function unregister(u:Unit){
			if(registered_unit_1 == u)
				registered_unit_1 = null;
			if(registered_unit_2 == u)
				registered_unit_2 = null;
		}
	}
}